package lzg.blog.config.application;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/*
* mybatis plus统一处理更新之前的操作
* todo parent模块对于登录用户信息的保存  日期类
* */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
        String field = "updateTime";
        String creatorField = "creator";
		boolean hasGetter = metaObject.hasGetter(field);
		boolean hasCreatorField = metaObject.hasGetter(creatorField);
		if (hasGetter) setFieldValByName(field, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),metaObject);
		if (hasCreatorField) setFieldValByName(creatorField,"test",metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {

	}
}
